<template>
  <div>
    <div class="d-sm-flex justify-content-between align-items-center mb-4">
      <h3 class="text-dark mb-0">个人资料</h3>
    </div>

    <div class="row">
      <div class="col-lg-6 col-xl-6">
        <el-card shadow="always">
          <div class="row justify-content-start feature">
            <p>姓名</p>
            <el-input v-model="ventor.vname"></el-input>
            <p>手机号</p>
            <el-input v-model="ventor.vtelephone"></el-input>
            <p>密码</p>
            <el-input v-model="ventor.vpassword"></el-input>
          </div>
          <el-button type="primary" size="small" style="margin-top: 10px;margin-bottom: 10px" @click="changeVentorInfo()">修改</el-button>
        </el-card>
      </div>

      <div class="col-lg-6 col-xl-6">
        <el-card shadow="always">
          <div class="row justify-content-start feature">
            <p>店铺名称</p>
            <el-input v-model="sname"></el-input>
          </div>
          <el-button type="primary" size="small" style="margin-top: 10px;margin-bottom: 10px" @click="changeStoreInfo()">修改</el-button>
        </el-card>
      </div>
    </div>

  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "Infos",
  data(){
    return{
      ventor:{
        vid:'',
        vname:'',
        vtelephone: '',
        vpassword: ''
      },
      sid: '',
      sname:'',
    }
  },
  methods:{
    changeVentorInfo(){
      if (this.ventor.vname ===''){
        this.$message.error("请输入姓名");
      } else if (this.ventor.vtelephone ===''){
        this.$message.error("请输入手机号");
      } else if (this.ventor.vpassword===''){
        this.$message.error("请输入密码");
      } else {
        axios.post('http://localhost:9001/ventor/updateVentor',this.ventor).then(res=>{
          this.$message.success("修改成功");
          this.getAllInfo();
        })
      }
    },
    changeStoreInfo(){
      if (this.sname ===''){
        this.$message.error("请输入店铺名称");
      } else {
        axios.get('http://localhost:9001/store/updateStore?sid='+this.sid+'&sname='+this.sname).then(res=>{
          this.$message.success("修改成功");
          this.getAllInfo();
        })
      }
    },
    getAllInfo(){
      axios.get('http://localhost:9001/ventor/selectVASByVid?vid='+sessionStorage.getItem("vid")).then(res=>{
        sessionStorage.setItem("vname",res.data.vname);
        sessionStorage.setItem("vpassword",res.data.vpassword);
        sessionStorage.setItem("vtelephone",res.data.vtelephone);
        sessionStorage.setItem("sname",res.data.sname);
      })
    },
    setInfo(){
      this.ventor.vid = sessionStorage.getItem("vid");
      this.ventor.vname = sessionStorage.getItem("vname");
      this.ventor.vtelephone = sessionStorage.getItem("vtelephone");
      this.ventor.vpassword = sessionStorage.getItem("vpassword");
      this.sid = sessionStorage.getItem("sid");
      this.sname = sessionStorage.getItem("sname");
    }
  },
  created() {
    this.setInfo();
  }
}
</script>

<style scoped>
p{
  margin-top: 10px;
}
</style>